package com.gitee.swsk33.kafkadynamicconsumer.api;

import org.apache.kafka.clients.admin.AdminClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;

@RestController
@RequestMapping("/api/kafka-topic")
public class KafkaTopicAPI {

	/**
	 * 在需要删除Topic的地方自动装配AdminClient对象
	 */
	@Autowired
	private AdminClient adminClient;

	@GetMapping("/delete/{topicId}")
	public String deleteTopic(@PathVariable String topicId) {
		adminClient.deleteTopics(Collections.singleton(topicId));
		return "删除Topic完成！";
	}

}